<?php
    date_default_timezone_set("PRC");
    $con = new mysqli("127.0.0.1", "root", "", "");
    if ( mysqli_connect_errno ()) {
         die('Could not connect: ' . $con->connect_error);
    }
    $con->query("SET NAMES utf8");

    if (!isset($_GET["way"])) {
        $way = "immediately";
    }
    else {
        $way = $_GET["way"];
    }

    $data = array();
    $data_time = array();

    $sql = "SELECT * FROM `content` ORDER BY `id` DESC";
    if ($result = $con->query($sql)) {
        while ($row = $result->fetch_assoc()) {
            array_push($data, $row["text"]);
            array_push($data_time, $row["time"]);
        }
    }
    else {
        array_push($data, "{'text':'error'}");
    }

    $return_data = array();
    foreach ($data as $key => $value) {
        $a = json_decode($value,true);
        if ($way == "immediately") {
            $h = intval(date("G", $data_time["$key"]));
            $m = intval(date("i", $data_time["$key"]));
            $s = intval(date("s", $data_time["$key"]));
            $a["time"] = ($h*3600+$m*60+$s)*10;
        }
        else {
            $a["time"] = $key+5;
        }
        $a = json_encode($a);
        array_push($return_data, $a);
    }
    $data = json_encode($return_data);

    echo $data;





